using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlTypes;
using MySql.Data.MySqlClient;

namespace FutureOpen.Core.func.sql
{
    /// <summary>
    /// for Sch
    /// </summary>
    public class SchProvider
    {        
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static readonly string SQL_ADD_SCH = "INSERT INTO sch(sch_name,sch_desc,sch_count) Values('{0}','{1}',{2});select last_insert_id();";
        public static int AddSCH(string title, string content)
        {
            string sql = string.Format(SQL_ADD_SCH, title, content, 0);
            return Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.CONNSTR(), sql, null));
        }

        public static readonly string SQL_ADD_COUNT_SCH = "update sch set sch_count=sch_count+1 where sch_id={0};";
        public static void AddCountSCH(int id)
        {
            string sql = string.Format(SQL_ADD_COUNT_SCH, id);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null); 
        }


        public static readonly string SQL_UPDATE_SCH = "update sch set sch_name='{1}',sch_desc='{2}' where sch_id={0};";
        public static void UpdateSch(int id, string title, string content)
        {
            string sql = string.Format(SQL_UPDATE_SCH, id, title, content);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
        }

        public static readonly string SQL_GET = "select * from sch where sch_id={0}";
        public static DataRow GetInfo(int id)
        {
            string sql = string.Format(SQL_GET, id);

            return MySqlHelper.ExecuteDatarow(MySqlHelper.CONNSTR(), sql, null);
        }
    }



    /// <summary>
    /// for Company
    /// </summary>
    public class CompanyProvider
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static readonly string SQL_ADD_Company = "INSERT INTO Company(Company_name,Company_desc,Company_count) Values('{0}','{1}',{2});select last_insert_id();";
        public static int AddCompany(string title, string content)
        {
            string sql = string.Format(SQL_ADD_Company, title, content, 0);
            return Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.CONNSTR(), sql, null));
        }

        public static readonly string SQL_ADD_COUNT_Company = "update Company set Company_count=Company_count+1 where Company_id={0};";
        public static void AddCountCompany(int id)
        {
            string sql = string.Format(SQL_ADD_COUNT_Company, id);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
        }


        public static readonly string SQL_UPDATE_Company = "update Company set Company_name='{1}',Company_desc='{2}' where Company_id={0};";
        public static void UpdateCompany(int id, string title, string content)
        {
            string sql = string.Format(SQL_UPDATE_Company, id, title, content);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
        }

        public static readonly string SQL_GET = "select * from Company where Company_id={0}";
        public static DataRow GetInfo(int id)
        {
            string sql = string.Format(SQL_GET, id);

            return MySqlHelper.ExecuteDatarow(MySqlHelper.CONNSTR(), sql, null);
        }
    }




    /// <summary>
    /// for Title
    /// </summary>
    public class TitleProvider
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public static readonly string SQL_ADD_Title = "INSERT INTO Title(Title_name,Title_desc,Title_count) Values('{0}','{1}',{2});select last_insert_id();";
        public static int AddTitle(string title, string content)
        {
            string sql = string.Format(SQL_ADD_Title, title, content, 0);
            return Convert.ToInt32(MySqlHelper.ExecuteScalar(MySqlHelper.CONNSTR(), sql, null));
        }

        public static readonly string SQL_ADD_COUNT_Title = "update Title set Title_count=Title_count+1 where Title_id={0};";
        public static void AddCountTitle(int id)
        {
            string sql = string.Format(SQL_ADD_COUNT_Title, id);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
        }


        public static readonly string SQL_UPDATE_Title = "update Title set Title_name='{1}',Title_desc='{2}' where Title_id={0};";
        public static void UpdateTitle(int id, string title, string content)
        {
            string sql = string.Format(SQL_UPDATE_Title, id, title, content);
            MySqlHelper.ExecuteNonQuery(MySqlHelper.CONNSTR(), sql, null);
        }

        public static readonly string SQL_GET = "select * from Title where Title_id={0}";
        public static DataRow GetInfo(int id)
        {
            string sql = string.Format(SQL_GET, id);

            return MySqlHelper.ExecuteDatarow(MySqlHelper.CONNSTR(), sql, null);
        }
    }
}
